import { getBanners } from "../api/banner.js";

export default {
    namespaced: true,
    state: {
        isLoading: false,
        banner: []
    },
    mutations: {
        setIsLoading(state, payload) {
            state.isLoading = payload;
        },
        setBanner(state, payload) {
            state.banner = payload;
        }
    },
    actions: {
        async fetchData(ctx) {
            if (ctx.state.banner.length) {
                return
            }
            ctx.commit("setIsLoading", true);
            const resp = await getBanners();
            ctx.commit("setBanner", resp.map((item)=>{
                return {
                    ...item,
                    midImg: item.midImg,
                    bigImg: item.midImg,
                }
            }));
            ctx.commit("setIsLoading", false);
        }
    }
}